Repository navigation
[net 11] Fix x:Reference NameScope resolution in lazy DataTemplate resources - #38093
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 38093Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 38093" |
|
Hey there @@Shalini-Ashokan! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
|
/azp run maui-pr-uitests , maui-pr-devicetests |
|
Azure Pipelines: Successfully started running 2 pipeline(s). |
This comment has been minimized.
This comment has been minimized.
MauiBot
left a comment
There was a problem hiding this comment.
AI Review Summary
@Shalini-Ashokan — new AI review results are available based on commit
8c92cc8.
🗂️ Review Sessions — click to expand
🚦 Gate — Test Before & After Fix
Gate Result: ❌ FAILED
Platform: IOS · Base: net11.0 · Merge base: dd86ae04
🩺 The PR's test does not compile — the build error is in one of the PR's own test files, which the gate never reverts, so it fails identically without and with the fix. This is NOT a pre-existing/environment failure — the PR must fix its test (e.g. an ambiguous using / type collision). Investigate the PR's test code.
CSC : error MAUIG1001: An error occured while parsing Xaml: ReferenceExtension: Name 'PageRoot' not found in any NameScope. [/Users/cloudtest/vss/_work/1/s/src/Controls/tests/Xaml.UnitTests/Controls.X...
| Test | Without Fix (expect FAIL) | With Fix (expect PASS) |
|---|---|---|
📄 Maui37551 Maui37551 |
🛠️ BUILD ERROR | 🛠️ BUILD ERROR |
📄 Tests Tests |
🛠️ BUILD ERROR | 🛠️ BUILD ERROR |
🔴 Without fix — 📄 Maui37551: 🛠️ BUILD ERROR · 24s
Error-relevant lines (filtered from the build log):
CSC : error MAUIG1001: An error occured while parsing Xaml: ReferenceExtension: Name 'PageRoot' not found in any NameScope. [/Users/cloudtest/vss/_work/1/s/src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj]
🟢 With fix — 📄 Maui37551: 🛠️ BUILD ERROR · 10s
Error-relevant lines (filtered from the build log):
CSC : error MAUIG1001: An error occured while parsing Xaml: ReferenceExtension: Name 'PageRoot' not found in any NameScope. [/Users/cloudtest/vss/_work/1/s/src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj]
🔴 Without fix — 📄 Tests: 🛠️ BUILD ERROR · 10s
Error-relevant lines (filtered from the build log):
CSC : error MAUIG1001: An error occured while parsing Xaml: ReferenceExtension: Name 'PageRoot' not found in any NameScope. [/Users/cloudtest/vss/_work/1/s/src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj]
🟢 With fix — 📄 Tests: 🛠️ BUILD ERROR · 9s
Error-relevant lines (filtered from the build log):
CSC : error MAUIG1001: An error occured while parsing Xaml: ReferenceExtension: Name 'PageRoot' not found in any NameScope. [/Users/cloudtest/vss/_work/1/s/src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj]
⚠️ Failure Details
- 🛠️ Maui37551 without fix: build failed before tests could run
CSC : error MAUIG1001: An error occured while parsing Xaml: ReferenceExtension: Name 'PageRoot' not found in any NameScope. [/Users/cloudtest/vss/_work/1/s/src/Controls/tests/Xaml.UnitTests/Controls.X...
- 🛠️ Tests without fix: build failed before tests could run
CSC : error MAUIG1001: An error occured while parsing Xaml: ReferenceExtension: Name 'PageRoot' not found in any NameScope. [/Users/cloudtest/vss/_work/1/s/src/Controls/tests/Xaml.UnitTests/Controls.X...
- 🛠️ Maui37551 with fix: build failed (fix does not compile)
CSC : error MAUIG1001: An error occured while parsing Xaml: ReferenceExtension: Name 'PageRoot' not found in any NameScope. [/Users/cloudtest/vss/_work/1/s/src/Controls/tests/Xaml.UnitTests/Controls.X...
- 🛠️ Tests with fix: build failed (fix does not compile)
CSC : error MAUIG1001: An error occured while parsing Xaml: ReferenceExtension: Name 'PageRoot' not found in any NameScope. [/Users/cloudtest/vss/_work/1/s/src/Controls/tests/Xaml.UnitTests/Controls.X...
📁 Fix files reverted (1 files)
src/Controls/src/SourceGen/KnownMarkups.cs
📋 Pre-Flight — Context & Validation
PR #38093 Pre-Flight
Context
- PR:
[WIP] [net 11] Fix x:Reference NameScope resolution in lazy DataTemplate resources - Issue: #37551, a .NET 11 regression where two or more
DataTemplateresources usingx:Referencecannot resolve a name in the containing page's namescope and compilation reportsMAUIG1001. - Base / head:
net11.0at merge basedd86ae04/ materialized review commitb7ff37b753. - Platform requested for this phase: iOS. The failure is in XAML source generation and is expected to be platform-independent.
PR Diff
The PR changes three files:
src/Controls/src/SourceGen/KnownMarkups.cs- Replaces two inline parent-walking loops with
GetParentElement(INode node). - The helper starts at
node.Parent, skips consecutiveListNodewrappers, and returns the firstElementNode. - It is used by both
TryResolveXReferenceSourceTypeandProvideValueForReferenceExtension.
- Replaces two inline parent-walking loops with
src/Controls/tests/Xaml.UnitTests/Issues/Maui37551.xaml- Adds a page named
PageRootwith two lazyDataTemplateresources. - One template uses direct
{x:Reference PageRoot}and the other uses{Binding Source={x:Reference PageRoot}}.
- Adds a page named
src/Controls/tests/Xaml.UnitTests/Issues/Maui37551.xaml.cs- Adds an inflator theory intended to validate both source-generation diagnostics and runtime template binding contexts.
The existing production fix assumes the failure is caused by advancing past the first real parent after a ListNode. Alternative candidates must use a different root-cause mechanism rather than relocating the same parent-skip logic.
Gate Evidence
The completed gate failed and must not be rerun. Both the without-fix and with-fix runs stop during compilation with:
CSC : error MAUIG1001: An error occured while parsing Xaml: ReferenceExtension: Name 'PageRoot' not found in any NameScope.
The gate identifies src/Controls/src/SourceGen/KnownMarkups.cs as the sole reverted production fix file. The two newly added test files remain present. No .github/.baseline-state.json exists after the gate's restore.
Candidate Boundaries
- Writable production target after baseline establishment:
src/Controls/src/SourceGen/KnownMarkups.cs, subject to the exactRevertedFilesallow-list emitted byEstablishBrokenBaseline.ps1. - Do not edit the PR's added XAML test files; the objective is an alternative production fix.
- Preserve all pre-existing unrelated worktree changes and untracked paths.
- Use only
pwsh .github/scripts/EstablishBrokenBaseline.ps1 -Restorefor restoration. - Each candidate gets one implementation/test pass and at most one focused correction/retest.
Test Contract
Primary test:
dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj --filter "Maui37551"Only after the primary test passes, run both mandatory regression tests:
dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj --filter "BindingDiagnosticsTests"
dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj --filter "Tests"A candidate is Pass only if the primary test and both regression tests pass. Any executed test failure makes it Fail; an unavailable required environment makes it Blocked.
🔬 Code Review — Deep Analysis
Code Review — PR #38093
Independent Assessment
What this changes: The production change centralizes XAML AST parent traversal in GetParentElement. Unlike the previous traversal, the helper begins at the immediate parent, skips only consecutive ListNode wrappers, and returns the first enclosing ElementNode. Both direct x:Reference generation and binding-source type inference use the helper. The regression fixture exercises direct and nested binding-source references from two DataTemplate resources to the containing page.
Inferred motivation: The former loop advanced once through a ListNode wrapper and then advanced again, which could skip the element whose namescope must be searched.
Approach assessment: The traversal correction is small, shared by the two affected lookup paths, and mechanically matches the inferred AST bug. It adds no public API or persistent state. The expert reviewer found no actionable file:line defect, so inline-findings.json is the valid empty array [].
Reconciliation with PR Narrative
The implementation agrees with the stated root cause and intended behavior. However, the trusted gate contradicts the claim that the submitted change fixes the regression: the PR's Maui37551.xaml still produces MAUIG1001 during project compilation with the production fix applied.
Prior Review Reconciliation
No prior ❌ Error findings were found on the queried review surfaces.
CI and Gate Status
- Trusted gate: failed
- Without fix: build stopped with
MAUIG1001, as expected for the regression. - With fix: build stopped with the same
MAUIG1001, so the test never executed. - Regression cross-reference:
BindingDiagnosticsTestspassed; the broad XAMLTestsfilter failed because the project could not compile. - Required GitHub checks: unavailable through the unauthenticated CLI; this does not supersede the supplied definitive gate failure.
Findings
No actionable inline code finding was established from static review. The blocking issue is behavioral: the required regression test does not compile with the submitted fix, so the PR has not demonstrated that its corrected traversal reaches PageRoot in the actual SourceGen pipeline.
Failure-Mode Probing
- Reference directly inside a lazy template: both lookup paths now stop at the immediate real parent rather than skipping it; static traversal is sound.
- Consecutive
ListNodewrappers: the helper skips all wrappers and returns the firstElementNode. - No parent or a non-element parent: the helper returns
null, terminating lookup without introducing a null dereference. - Unrelated XAML: the helper is reached only while resolving
x:Reference; there is no startup, platform-handler, static-state, or lifecycle impact. - Empirical path: despite the sound local transformation, the supplied with-fix gate reaches the unresolved-reference diagnostic. That unresolved discrepancy prevents a safety recommendation.
External Output Contract
Not applicable.
Trim/AOT Evidence Chain
Not applicable.
Verdict: NEEDS_CHANGES
Confidence: low
Summary: Static review supports the parent-traversal correction and found no inline defect, but the trusted with-fix gate still fails on the exact diagnostic the PR is intended to remove. The submitted candidate cannot be approved until the regression fixture compiles and the required targeted tests pass, or the gate failure is conclusively shown to arise from stale build-task artifacts.
🛠️ Try-Fix — Analysis & Comparison
Try-Fix Candidates Aggregate — PR #38093
| Candidate | Attempt Dir | Result | Primary Test | Regressions | Findings | Restore Outcome |
|---|---|---|---|---|---|---|
| 1 | CustomAgentLogsTmp/PRState/38093/PRAgent/try-fix/attempt-1 |
Blocked | Not run (baseline blocked) | Not run | 0 | No baseline state found (Restored False) |
| 2 | CustomAgentLogsTmp/PRState/38093/PRAgent/try-fix/attempt-2 |
Blocked | Not run (baseline blocked) | Not run | 0 | No baseline state found (Restored False) |
Candidate 1 Narrative
Approach
Designed but did not implement a fallback from deferred DataTemplate lookup to the owning page/root namescope, so PageRoot would be resolved from the outer root scope.
Prior approach avoided
Candidate 1 avoided the existing PR's GetParentElement(INode) mechanism, which starts at node.Parent, skips ListNode wrappers, and resumes ancestor-based compile-time namescope lookup. The gate still failed with ReferenceExtension: Name 'PageRoot' not found in any NameScope.
Mechanism-level difference
Instead of changing AST parent traversal, candidate 1 intended to target the owning page/root namescope directly, bypassing the template-local scope boundary.
Baseline / edit boundary result
EstablishBrokenBaseline.ps1 failed with DIRTY WORKING DIRECTORY; .github/.baseline-state.json was absent, so no RevertedFiles allow-list existed. The candidate was blocked before editing.
Files changed
No production files. Candidate 1 created only its attempt artifacts under CustomAgentLogsTmp/PRState/38093/PRAgent/try-fix/attempt-1/ and its narrative artifact.
Full captured diff
Exact test commands and results
dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj --filter "Maui37551"— Not rundotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj --filter "BindingDiagnosticsTests"— Not rundotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj --filter "Tests"— Not run
Failure analysis
Mandatory baseline establishment rejected the pre-existing dirty tracked worktree and produced no modification allow-list. Protocol therefore prohibited production edits and testing. The result was Blocked.
Inline expert self-review
reviewer-findings.json was []; finding count: 0.
Restore confirmation
pwsh .github/scripts/EstablishBrokenBaseline.ps1 -Restore ran and reported No baseline state found. Nothing to restore. (Restored False), the accepted no-state outcome after no edits.
Candidate 2 Narrative
Approach
Designed but did not implement a runtime-delegation fix: if SourceGen's known ReferenceExtension fast path cannot resolve a name in a lazy-resource context, it would return false without reporting MAUIG1001. NodeSGExtensions.TryProvideValue would then fall through to the existing generic IMarkupExtension.ProvideValue path, whose generated IReferenceProvider includes the current and parent generation-context scopes.
Prior approaches avoided
Candidate 2 avoided both prior mechanisms:
- It did not repair the PR's compile-time AST parent walk or skip
ListNodewrappers. - It did not add candidate 1's special owning-page/root-namescope fallback.
Mechanism-level difference
The mechanism changes resolution timing and execution path. Rather than selecting a different compile-time ancestor or root, it lets the established runtime markup-extension pipeline perform reference resolution through its generated service-provider scope array when the lazy resource factory executes.
Baseline / edit boundary result
EstablishBrokenBaseline.ps1 again failed with DIRTY WORKING DIRECTORY; .github/.baseline-state.json was absent and no RevertedFiles allow-list existed. The candidate was blocked before editing.
Files changed
No production files. Candidate 2 created its attempt artifacts under CustomAgentLogsTmp/PRState/38093/PRAgent/try-fix/attempt-2/ and updated the required candidate/aggregate narratives.
Full captured diff
Exact test commands and results
dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj --filter "Maui37551"— Not run (baseline blocked)dotnet test src/Controls/tests/SourceGen.UnitTests/SourceGen.UnitTests.csproj --filter "BindingDiagnosticsTests"— Not run (primary did not pass)dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj --filter "Tests"— Not run (primary did not pass)
Failure analysis
The baseline script rejected extensive pre-existing tracked changes and produced no allow-list. Editing KnownMarkups.cs without that state would violate restoration guarantees, so candidate 2 is Blocked and its mechanism remains untested.
Inline expert self-review
The empty candidate diff was reviewed inline against the required principles and always-active dimensions. reviewer-findings.json is []; finding count: 0.
Artifact gate
All eight mandatory attempt artifacts were present.
Restore confirmation
pwsh .github/scripts/EstablishBrokenBaseline.ps1 -Restore ran and reported No baseline state found. Nothing to restore. (Restored False), the expected no-state outcome because no candidate edit occurred.
Final STEP 5a Outcome
Both explicitly bounded candidates are Blocked by the same mandatory baseline-establishment guard. Neither candidate changed production code or ran tests. Candidate 2 is the final candidate; no further candidate is proposed.
📝 PR Finalize — Recommended Title & Description
Assessment: ✏️ Recommend updating — the current title includes workflow noise, while the all-platform validation checklist is not supported by this platform-independent SourceGen diff and the added regression fixture should be documented explicitly.
Recommended title
[XAML] SourceGen: Fix x:Reference namescope traversal in DataTemplate resources
Recommended description
### Issue Details
Multiple `DataTemplate` resources can use `x:Reference` to access a named element outside the template. When these templates are generated as lazy resources, SourceGen can report that the name cannot be found, causing the build to fail with `MAUIG1001`.
### Root Cause
SourceGen walks upward through the XAML tree to find the requested name. When an internal `ListNode` is encountered, the previous traversal moved through the list wrapper and then advanced again, skipping the real parent `ElementNode` whose namescope must be searched.
### Description of Change
Add `GetParentElement(INode)` to start at the immediate parent, skip only internal `ListNode` wrappers, and return the first real parent `ElementNode`. Use the helper for both direct `x:Reference` generation and `Binding.Source={x:Reference ...}` source-type resolution.
Add the `Maui37551` XAML regression fixture with two `DataTemplate` resources:
- A direct `{x:Reference PageRoot}`
- A `{Binding Source={x:Reference PageRoot}}`
### Platform Notes
The change is in the platform-independent XAML SourceGen pipeline; no Android, iOS, Mac Catalyst, or Windows platform-specific source is changed.
### Issues Fixed
Fixes #37551
### Output Screenshot
| Before | After |
|---|---|
| <video src="https://github.com/user-attachments/assets/60ba519f-65f6-4893-a7d1-8bba23dc3cf1"> | <video src="https://github.com/user-attachments/assets/0b9deb16-a494-4182-801c-7ac8472d31a3"> |
🏁 Report — Final Recommendation
⚠️ Final Recommendation: REQUEST CHANGES
Winner: pr
The raw PR is the only candidate with an implemented production change and regression fixture. Its shared GetParentElement correction is the strongest available mechanism on static review, but it is not merge-ready: the trusted gate still emits MAUIG1001 with the fix applied, and the broad XAML regression selection fails during compilation.
Comparative ranking
| Rank | Candidate | Implementation | Validation | Expert findings | Decision |
|---|---|---|---|---|---|
| 1 | pr |
Concrete, localized correction used by both direct and binding-source x:Reference paths |
Failed: with-fix Maui37551 build still reports MAUIG1001; BindingDiagnosticsTests passed, broad XAML Tests failed at compile time |
No actionable inline findings | Winner, because it is the only implemented candidate, but it requires changes or conclusive build-task evidence before approval |
| 2 | pr-plus-reviewer |
Source-identical to pr; expert review supplied no actionable patch |
Blocked: required build-task rebuild failed once with missing candidate-local project.assets.json; targeted tests were not run |
inline-findings.json is []; reviewer.patch is empty |
Cannot outrank pr: it adds neither code nor successful evidence and inherits the gate failure |
| 3 | try-fix-1 |
Concept only: resolve through an owning page/root namescope fallback | Blocked before implementation or tests by baseline establishment | Empty self-review over an empty diff | Unrankable as a fix; no production diff or empirical evidence |
| 4 | try-fix-2 |
Concept only: defer unresolved known-markup handling to runtime IMarkupExtension.ProvideValue |
Blocked before implementation or tests by baseline establishment | Empty self-review over an empty diff | Unrankable as a fix; broader timing/behavior change remains untested |
Why pr wins
- It directly fixes the demonstrated double-advance in the AST parent walk while preserving the existing namescope-resolution model.
- It applies the same traversal rule to both affected SourceGen paths instead of introducing separate fallback behavior.
- Every alternative is either source-identical and blocked (
pr-plus-reviewer) or merely conceptual with an empty diff (try-fix-1,try-fix-2).
Blocking evidence
- The trusted Gate is authoritative for approval and failed.
- Both without-fix and with-fix runs stopped on
ReferenceExtension: Name 'PageRoot' not found in any NameScope. - The regression cross-reference reports one pass (
BindingDiagnosticsTests) and one failure (broad XAMLTests). - No candidate passed the primary test plus both mandatory regressions. Accordingly, no failed candidate has been ranked above a passing candidate; there is no passing candidate in this set.
Required disposition
Keep the raw PR mechanism as the leading implementation, but request changes until the submitted regression fixture compiles with the fix and all required targeted validations pass, or until the with-fix gate failure is conclusively attributed to stale SourceGen build-task artifacts and replaced with valid candidate-root evidence.
🔗 Regression Cross-Reference
🔍 Regression Cross-Reference
⚠ Overlaps with prior bug-fix PRs — same files modified, but no exact line revert detected.
| File | Fix PR | Fixed issue(s) |
|---|---|---|
src/Controls/src/SourceGen/KnownMarkups.cs |
#34501 | #34490 |
🧪 Regression Tests to Verify
These tests were added by the overlapping fix PRs. Running them to verify no side-effect regressions:
| Fix PR | Type | Test | Filter |
|---|---|---|---|
| #34501 | UnitTest | BindingDiagnosticsTests | BindingDiagnosticsTests |
| #34501 | XamlUnitTest | Tests | Tests |
🧪 Regression Test Results
❌ FAILED — 1 passed, 1 failed, 0 skipped
| Fix PR | Test | Type | Result |
|---|---|---|---|
| #34501 | BindingDiagnosticsTests | UnitTest | ✅ PASSED |
| #34501 | Tests | XamlUnitTest | ❌ FAILED |
📱 UI Tests — Button,Label,Layout
Detected UI test categories: Button,Label,Layout
❌ Deep UI tests — 353 passed, 2 failed, 8 skipped across 3 categories on platform-pool agent (replaces in-process counts above).
🧪 UI Test Execution Results (deep, platform pool)
| Category | Tests | Snapshot diffs |
|---|---|---|
Button |
69/72 (2 ❌, 1 skipped) | — |
Label |
90/92 (2 skipped) ✓ | — |
Layout |
194/199 (5 skipped) ✓ | — |
🔍 AI analysis of failures — PR-related vs unrelated
🔍 AI-generated triage (GitHub Copilot CLI) — a heuristic judgement of whether each deep UI test failure is connected to this PR's changes. Verify before relying on it.
Likely unrelated: the failures appear pre-existing, flaky, or infrastructure.
- ● Unrelated — Button fixture element-discovery timeouts (~2 tests): both tests time out before reaching their button layout assertions, and the fixture XAML uses neither
x:ReferencenorDataTemplate, so it does not exercise the source-generator namescope logic changed by this PR.
Strongest signal: both iOS failures share the generic “Timed out waiting for element” pattern at the fixture’s first lookup rather than failing a measurement or screenshot assertion.
❌ Button — 2 failed tests
ButtonLayoutResizesWithImagePosition
System.TimeoutException : Timed out waiting for element...
at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2785
at UITest.Appium.HelperExtensions.WaitForAtLeastOne(Func`1 query, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2812
at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 797
at Microsoft.Maui.TestCases.Tests.Issues.Issue22306_1.ButtonLayoutResizesWithImagePosition() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue22306_1.cs:line 29
at System.RuntimeMethodHandle.InvokeMethod(ObjectHandleOnStack target, Void** arguments, ObjectHandl
...
ButtonMeasuresLargerThanDefault
System.TimeoutException : Timed out waiting for element...
at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2785
at UITest.Appium.HelperExtensions.WaitForAtLeastOne(Func`1 query, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2812
at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 797
at Microsoft.Maui.TestCases.Tests.Issues.Issue22306_1.ButtonMeasuresLargerThanDefault() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue22306_1.cs:line 19
at NUnit.Framework.Internal.TaskAwaitAdapter.GenericAdapter`1.BlockUntilCompleted()
at NUnit.Framework
...
📎 Download drop-deep-uitests artifact (TRX + snapshot diffs)
🧭 Next Steps — review latest findings
No alternative fix was selected for this run. Review the session findings and CI results before merging.
|
The gate failed because its with-fix run reused the stale SourceGen/Build.Tasks artifacts generated during the without-fix run. |
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
🟢 Approval recommended
The fix is targeted and covered by a new regression test; only a minor maintainability nit was found.
Pull request overview
Fixes a .NET MAUI XAML SourceGen name-scope traversal bug that caused x:Reference resolution to fail (MAUIG1001) when multiple DataTemplate resources are present, and adds a regression test to cover the scenario.
Changes:
- Adjusted SourceGen’s upward tree traversal to skip only internal
ListNodewrappers and stop at the first real parent element. - Applied the corrected traversal to both binding-source and
ReferenceExtensionresolution paths. - Added an issue regression test (
Maui37551) validating both directx:Referenceand{Binding Source={x:Reference ...}}across inflators.
File summaries
| File | Description |
|---|---|
| src/Controls/src/SourceGen/KnownMarkups.cs | Fixes parent traversal logic used by SourceGen name-scope resolution for x:Reference and binding-source lookup. |
| src/Controls/tests/Xaml.UnitTests/Issues/Maui37551.xaml | Adds a repro XAML with two DataTemplate resources referencing the page root name-scope. |
| src/Controls/tests/Xaml.UnitTests/Issues/Maui37551.xaml.cs | Adds a regression test asserting MAUIG1001 is not produced (SourceGen) and runtime binding contexts resolve to the page. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 1
- Review effort level: Lite
| static ElementNode? GetParentElement(INode node) | ||
| { | ||
| INode? parent = node.Parent; | ||
| while (parent is ListNode listNode) | ||
| parent = listNode.Parent; | ||
| return parent as ElementNode; | ||
| } |
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Issue Details
Multiple DataTemplate resources can use x:Reference to access a named element outside the template.
When these templates are generated as lazy resources, SourceGen incorrectly reports that the name cannot be found.
This causes the build to fail with MAUIG1001.
Root Cause
SourceGen walks upward through the XAML tree to find the requested name.
When an internal ListNode is encountered, the old code moves up once to skip the list and then moves up again.
That second movement skips the real parent element that must be searched.
Description of Change
The new helper starts at the immediate parent and skips only internal ListNode wrappers.
It returns the first real parent element instead of moving past it.
Both direct x:Reference and binding-source resolution now use this corrected traversal.
Validated the behavior in the following platforms
Issues Fixed
Fixes #37551
Output ScreenShot
37551-BeforeFix.mov
37551-AfterFix.mov